<template>
	<view class="content">
		<view class="input-group">
			<view class="uni-flex-btw border ">
				<text class="title uni-cell-20">联系人：</text>
				<input type="text" class="uni-cell-80" focus clearable v-model="form.name" placeholder="请输入联系人"/>
			</view>
			<view class="uni-flex-btw border">
				<text class="title uni-cell-20">手机号：</text>
				<input type="number" class="uni-cell-80" clearable  v-model="form.tel" placeholder="请输入联系人手机号"/>
			</view>
			<view class="uni-flex-center tenance-foot"><button class="foot-btn" plain 
			 @tap="add">添加</button></view>
		</view>
	</view>
</template>

<script>
import {addPerson} from "@/api/person.js";
export default {
	data() {
		return {
			form:{
				name: '',
				tel: '',
			}
		};
	},
	onNavigationBarButtonTap(res){
		this.register();
	},
	methods: {
		isPhone(e) {
			console.log(JSON.stringify(e));
			let phone = e;
			var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
			if (myreg.test(phone) === false) {
				uni.showToast({
					icon: 'none',
					title: '请输入正确的手机号'
				});
				return false;
			}
			return true;
		},
		add() {
			const data = {
				name: this.name,
				tel: this.tel,
			};
			if(!this.form.name){
				uni.showToast({
					icon:'none',
					title: '联系人不能为空'
				});
				return;
			}
			const isphone =  this.isPhone(this.form.tel);
			if(isphone){
				addPerson(this.form).then((res)=>{
					if(res.data.code==0){
						uni.showToast({
							icon:'none',
							title: '用户添加成功'
						});
						uni.navigateBack()
					}else{
						uni.showToast({
							icon:'none',
							title: '用户添加成功'
						});
					}
				})
			}
		}
	}
};
</script>

<style lang="less" scoped>
	.tenance-foot{
		width: 100%;
		height: 180rpx;
		margin-top:180rpx;
		background-color: #fff;
		padding: 40rpx 24rpx;
		box-sizing: border-box;
	}
	.foot-btn {
		width: 100%;
		height: 90rpx;
		line-height: 90rpx;
		border-radius: 8rpx;
		color: #ffffff;
		margin-left: 0;
		background: #ffcf5a;
		border: none!important;
		font-size: 30rpx;
	}
	.foot-btn:active {
		opacity: 0.8;
	}
	.border{
		height: 80upx;
		line-height: 80upx;
		padding: 10upx;
		border-bottom: 1upx solid #EEEEEE;
	}
	.border input{
		height: 80upx;
		line-height: 80upx;
	}
</style>
